using System.Drawing.Imaging;
using System.IO;
using Microsoft.AspNetCore.Mvc;
using Geekeradmin.Common;
using Publicuse.Util;

namespace Geekeradmin.Controllers.other
{
    public class VerifyCodeController : Controller
    {
        /// <summary>
        /// 数字验证码
        /// </summary>
        /// <returns></returns>
        public FileContentResult NumberVerifyCode()
        {
            string code = VerifyCodeUtil.GetSingleObj().CreateVerifyCode(VerifyCodeUtil.VerifyCodeType.NumberVerifyCode);
            byte[] codeImage = VerifyCodeUtil.GetSingleObj().CreateByteByImgVerifyCode(code, 100, 40);
            return File(codeImage, @"image/jpeg");
        }

        /// <summary>
        /// 字母验证码
        /// </summary>
        /// <returns></returns>
        public FileContentResult AbcVerifyCode()
        {
            string code = VerifyCodeUtil.GetSingleObj().CreateVerifyCode(VerifyCodeUtil.VerifyCodeType.AbcVerifyCode);
            var bitmap = VerifyCodeUtil.GetSingleObj().CreateBitmapByImgVerifyCode(code, 100, 40);
            MemoryStream stream = new MemoryStream();
            bitmap.Save(stream, ImageFormat.Png);
            return File(stream.ToArray(), "image/png");
        }

        /// <summary>
        /// 混合验证码
        /// </summary>
        /// <returns></returns>
        public FileContentResult MixVerifyCode()
        {
            string code = VerifyCodeUtil.GetSingleObj().CreateVerifyCode(VerifyCodeUtil.VerifyCodeType.MixVerifyCode);
            var bitmap = VerifyCodeUtil.GetSingleObj().CreateBitmapByImgVerifyCode(code, 100, 40);
            MemoryStream stream = new MemoryStream();
            bitmap.Save(stream, ImageFormat.Gif);
            return File(stream.ToArray(), "image/gif");
        }
    }
}
